<!--產品展示-->
<template>
  <div>
    <div class="item-detail-show">
      <div class="item-detail-left">
        <div class="item-detail-big-img">
          <img :src="product.picUrl" alt="">
        </div>
        <!--        <div class="item-detail-img-row">-->
        <!--          <div class="item-detail-img-small" v-for="(item, index) in goodsInfo.goodsImg" :key="index" @mouseover="showBigImg(index)">-->
        <!--            <img :src="item" alt="">-->
        <!--          </div>-->
        <!--        </div>-->
      </div>
      <div class="item-detail-right">
        <div class="item-detail-title">
          <p>
            <span class="item-detail-express">校园配送</span>{{ product.productName }}
          </p>
        </div>
        <div class="item-detail-tag">
          <p>
            <span v-text="product.description"></span>
          </p>
        </div>
        <div class="item-detail-price-row">
          <div class="item-price-left">
            <div class="item-price-row">
              <p>
                <span class="item-price-title">B I T 价</span>
                <span class="item-price" v-text="product.price"></span>
              </p>
            </div>
            <div class="item-price-row">
              <p>
                <span class="item-price-title">供应商</span>
                <span class="item-price-title">{{ product.supplierName }}</span>
              </p>
            </div>
            <div class="item-price-row">
              <p>
                <span class="item-price-title">产地</span>
                <span class="item-price-title">{{ product.supplierAddress }}</span>
              </p>
            </div>
          </div>
          <div class="item-price-right">
            <div class="item-remarks-sum">
              <p>库存</p>
              <p>
                <span class="item-remarks-num">{{ product.inventory }}</span>
              </p>
            </div>
          </div>
        </div>
        <!-- 选择颜色 -->
        <div class="item-select">
          <div class="item-select-title">
            <p>选择套餐</p>
          </div>
          <div class="item-select-column">
            <div class="item-select-row">
              <div class="item-select-box" v-for="(item, index1) in product.productTypeList" :key="index1"
                @click="select(index1)" :class="{ 'item-select-box-active': (index1) === selected }">
                <div class="item-select-intro">
                  <p>{{ item.productTypeName }}</p>
                </div>
              </div>
            </div>
          </div>
        </div>
        <br>
        <div class="add-buy-car-box">
          <div class="add-buy-car">
            <InputNumber :min="1" max="this.$route.query.inventory" v-model="count" size="large"
              readonly="this.product.restTime==null?readonly:null"></InputNumber>
            <Button type="error" size="large" @click="addCart">{{ this.product.restTime == null ? '加入购物车' : '秒杀' }}</Button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import store from '@/vuex/store';
import { mapActions } from 'vuex';
import { productDetailInfo } from '@/api/category';
// import {addTocart} from '../../api/cart';
// import {PayForSecGoods} from '../../api/order';
import { addTocart } from '../../api/cart';
import { PayForSecGoods } from '../../api/order';

export default {
  name: 'ShowGoods',
  data() {
    return {
      price: 0,
      count: 1,
      selected: 0,
      imgIndex: 0,
      product: {},
      productId: this.$route.query.productId,
      account: this.$route.query.account,
      // 设置可见性
      see: ''
    };
  },
  methods: {
    ...mapActions(['addShoppingCart']),
    init(url, config) {
      productDetailInfo(this.productId).then((res) => {
        console.log(res.data);
        // 处理类型
        // product获取数据
        this.product = res.data.data;
        console.log(this.product);
      });
    },
    select(index1) {
      this.selected = index1;
      this.price = this.product.price;
    },
    showBigImg(index) {
      this.imgIndex = index;
    },
    addCart() {
      this.$router.push('/ShoppingCart');
      // 不是秒杀产品
      if (this.product.restTime == null) {
        if (this.selected == null || this.selected === undefined) {
          this.$Message.warning('请选择一种规格');
        } else {
          // eslint-disable-next-line camelcase
          let cart_mall = {
            productAmount: this.count,
            productId: this.productId,
            // productTypeId: this.selected + 1
            // productTypeName: this.product.productTypeNameList[this.selected],
            // productTypeId: this.product.productTypeNameList[this.selected]
            productTypeId: this.product.productTypeList[this.selected].productTypeId
          };
          // console.log(cart_mall.productAmount);
          // console.log(cart_mall.productId);
          // console.log('fgewehrjtjtjt');
          // console.log(this.product.productTypeList[0].productTypeId);
          // productTypeName: this.product.productTypeNameList[this.selected];
          console.log(this.product.productTypeNameList);
          console.log(cart_mall.productTypeName);

          addTocart(cart_mall).then(res => {
            if (res.data.code === '00000') {
              this.$Message.success(res.data.message);
            } else {
              this.$Message.error('您未登录，无法加购！');
              this.$router.push({
                path: '/login'
              });
            }
          });
        };
      } else {
        // 秒杀产品
        if (this.selected == null || this.selected === undefined) {
          this.$Message.warning('请选择一种规格');
        } else {
          // eslint-disable-next-line camelcase
          let seccart_mall = {
            // customerAddrId: 1,
            productId: this.productId,
            productTypeName: this.product.productTypeName
          };
          console.log(seccart_mall.productId);
          console.log(seccart_mall.productTypeId);
          console.log(seccart_mall);
          // console.log(PayForSecGoods);
          PayForSecGoods(seccart_mall).then(res => {
            console.log(seccart_mall);
            console.log('我来到这里啦！');
            console.log('是这里的问题吗');
            console.log(res.data.code);
            if (res.data.code === '00000') {
              console.log('我来到这里啦！');
              console.log('Deadline');
              // this.$Message.success(res.data.message);
              // 转到付款界面
              this.$router.push({
                path: '/pay'
              });
              // this.$router.push('/payDone');
              console.log(res.data);
            } else {
              this.$Message.error('您未登录，无法秒杀！');
              this.$router.push({
                path: '/login'
              });
            }
          }).catch(error => {
            this.$Message.error(error.message);
          });
        }
      }
    },
    addShoppingCartBtn() {
      const index1 = parseInt(this.selectBoxIndex / 3);
      const index2 = this.selectBoxIndex % 3;
      const data = {
        goods_id: this.productId,
        title: this.product.description,
        productAmount: this.count,
        package: this.goodsInfo.setMeal[index1][index2]
      };
      this.addShoppingCart(data);
      this.$router.push({
        path: '/shoppingCart',
        query: {
          account: this.account,
          productAmount: this.count,
          productId: this.productId,
          productTypeId: this.productTypeId
        }

      });
    }
  },

  // 生命周期钩子函数，初始化数据
  mounted() {
    this.init();
  },
  store
};
</script>

<style scoped>
/******************商品图片及购买详情开始******************/
.item-detail-show {
  width: 80%;
  margin: 15px auto;
  display: flex;
  flex-direction: row;
  background-color: #fff;
}

.item-detail-left {
  width: 350px;
  margin-right: 30px;
}

.item-detail-big-img {
  width: 350px;
  height: 350px;
  box-shadow: 0px 0px 8px #ccc;
  cursor: pointer;
}

.item-detail-big-img img {
  width: 100%;
}

.item-detail-img-row {
  margin-top: 15px;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}

.item-detail-img-small {
  width: 68px;
  height: 68px;
  box-shadow: 0px 0px 8px #ccc;
  cursor: pointer;
}

.item-detail-img-small img {
  width: 100%;
}

/*商品选购详情*/
.item-detail-right {
  display: flex;
  flex-direction: column;
}

.item-detail-title p {
  color: #666;
  font-size: 20px;
}

.item-detail-express {
  font-size: 14px;
  padding: 2px 3px;
  border-radius: 3px;
  background-color: #e4393c;
  color: #fff;
}

/*商品标签*/
.item-detail-tag {
  font-size: 12px;
  color: #e4393c;
}

/*价格详情等*/
.item-detail-price-row {
  padding: 5px;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  background-color: #f3f3f3;
}

.item-price-left {
  display: flex;
  flex-direction: column;
}

.item-price-title {
  color: #999999;
  font-size: 14px;
  margin-right: 15px;
}

.item-price-row {
  margin: 5px 0px;
}

.item-price {
  color: #e4393c;
  font-size: 23px;
  cursor: pointer;
}

.item-price-full-cut {
  margin-right: 5px;
  padding: 3px;
  color: #e4393c;
  font-size: 12px;
  background-color: #ffdedf;
  border: 1px dotted #e4393c;
  cursor: pointer;
}

.item-remarks-sum {
  padding-left: 8px;
  border-left: 1px solid #ccc;
}

.item-remarks-sum p {
  color: #999999;
  font-size: 12px;
  line-height: 10px;
  text-align: center;
}

.item-remarks-num {
  line-height: 18px;
  color: #005eb7;
}

.item-select {
  display: flex;
  flex-direction: row;
  margin-top: 15px;
}

.item-select-title {
  color: #999999;
  font-size: 14px;
  margin-right: 15px;
}

.item-select-column {
  display: flex;
  flex-direction: column;
}

.item-select-row {
  display: flex;
  flex-direction: row;
  margin-bottom: 8px;
}

.item-select-box {
  display: flex;
  flex-direction: row;
  align-items: center;
}

.item-select-img {
  width: 36px;
}

.item-select-box {
  padding: 5px;
  margin-right: 8px;
  background-color: #f7f7f7;
  border: 0.5px solid #ccc;
  cursor: pointer;
}

.item-select-box:hover {
  border: 0.5px solid #e3393c;
}

.item-select-box-active {
  border: 0.5px solid #e3393c;
}

.item-select-img img {
  width: 100%;
}

.item-select-intro p {
  margin: 0px;
  padding: 5px;
}

.item-select-class {
  padding: 5px;
  margin-right: 8px;
  background-color: #f7f7f7;
  border: 0.5px solid #ccc;
  cursor: pointer;
}

.item-select-class:hover {
  border: 0.5px solid #e3393c;
}

.add-buy-car-box {
  width: 100%;
  margin-top: 15px;
  border-top: 1px dotted #ccc;
}

.add-buy-car {
  margin-top: 15px;
}

.address-container {
  margin-top: 15px;
}

.address-box {
  margin-top: 15px;
  padding: 15px;
  border: 1px #ccc dotted;
}

.address-check {
  margin: 15px 0px;
  height: 36px;
  display: flex;
  align-items: center;
}

.address-check-name {
  width: 120px;
  display: flex;
  justify-content: center;
  align-content: center;
  background-color: #ccc;
}

.address-check-name span {
  width: 120px;
  height: 36px;
  font-size: 14px;
  line-height: 36px;
  text-align: center;
  color: #fff;
  background-color: #f90013;
}

.address-detail {
  padding-left: 15px;
  font-size: 14px;
  color: #999999;
}

/******************商品图片及购买详情结束******************/
</style>
